class WorkItem < ActiveRecord::Base
  belongs_to :event
  has_many :tasks,:order=>"position",:dependent=>:destroy

  def rate
    if tasks.count!=0
      completed_count * 100 / count
    end
  end

  def count
    tasks.count
  end

  def completed_count
    tasks.count :conditions=>'completed=1'
  end

  def completed_tasks
    tasks.find(:all,:conditions=>'completed=1')
  end

  def uncompleted_tasks
    tasks-completed_tasks
  end

end